package com.letv.thrift;

import java.util.ArrayList;
import java.util.List;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

import serving.GenericDetailRequest;
import serving.GenericDetailServing;

/**
 * test thrift client
 * 
 * @author tanlu
 *
 */
public class ThriftClientTestNew {

	public static void main(String[] args) {
		try {
			// if (args.length < 2) {
			// System.err.println("Useage:java SimpleExample [servers]");
			// System.err.println("Useage:ip id");
			// System.exit(1);
			// }
			// String ip = args[0];
			// String id = args[1];

			// 印度ip
			// String ip = "10.121.152.28";
			// sarr.albumdetail.server=202.47.215.111:9090;202.47.215.112:9090;202.47.215.113:9090;202.47.215.114:9090

			// 国内详情
			// String ip = "10.130.208.66";
			// String ip = "10.11.145.3";

			// 北美环境
			// String ip = "107.155.52.72";

			// 北美测试环境
			// String ip = "10.120.14.144";

			// 国内测试机
			String ip = "10.154.156.157";
			String id = "205_356997";
			// String id = "205_356954";
			// String id = "205_356951";
			// String id = "202_979345375570471673";

			TTransport transport = new TFastFramedTransport(new TSocket(ip, 9090, 200000));
			TProtocol protocol = new TBinaryProtocol(transport, true, true);
			GenericDetailServing.Client client = new GenericDetailServing.Client(protocol);
			GenericDetailRequest request = new GenericDetailRequest();
			List<String> ids = new ArrayList<String>();
			request.setVideo_list_num((short) 50);
			ids.add(id);

			request.setIds(ids);
			transport.open();
			for (int i = 0; i < 1; i++) {
				long crrent = System.currentTimeMillis();
				System.out.println(client.GetDetailInfo(request));
				System.out.println("use time:" + (System.currentTimeMillis() - crrent));
			}
			// List<SourceLogo> logoList = client.getAllSourceLogos();
			// for (SourceLogo logo : logoList) {
			// System.out.println(logo);
			// }
			// SourceLogo logo = client.getSourceLogoBySourceName("vimeo");
			// System.out.println(logo);
			// transport.close();

		} catch (TTransportException e) {
			e.printStackTrace();
		} catch (TException x) {
			x.printStackTrace();
		}
	}
}
